package com.only.common.enums;



import cn.hutool.core.map.MapUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;

import java.util.Map;

/**
 * @author only
 * @date 2023/6/14
 * @description
 */
public class GeneralCodeEnumConverterFactory implements ConverterFactory<String, GeneralCodeEnum> {
    @SuppressWarnings("rawtypes")
    private static final Map<Class, Converter> Converters = MapUtil.newHashMap();

    @Override
    public <T extends GeneralCodeEnum> Converter<String, T> getConverter(Class<T> targetType) {
        Converter<String, T> converter = Converters.get(targetType);

        if (converter == null) {
            converter = new GeneralCodeEnumConverter<>(targetType);
            Converters.put(targetType, converter);
        }

        return converter;
    }
}
